package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * Servlet that reads a code snippet from the request and displays it inside a
 * PRE tag. Fails to filter the special HTML characters.
 */
public class BadCodeServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String title = "Code Sample";
		String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "
				+ "Transitional//EN\">\n";
		out.println(docType + "<HTML>\n" + "<HEAD><TITLE>" + title
				+ "</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n"
				+ "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" + "<PRE>\n"
				+ getCode(request) + "</PRE>\n"
				+ "Now, wasn't that an interesting sample\n" + "of code?\n"
				+ "</BODY></HTML>");
	}

	protected String getCode(HttpServletRequest request) {
		return (request.getParameter("code"));
	}
}